<template>
  <el-dialog :visible.sync="dialog" :close-on-click-modal="false" :before-close="cancel"
             :title="'输入条件'" append-to-body width="570px">
    <el-form ref="form" :inline="true" :model="form" size="small" label-width="66px">
      <el-form-item label="表名" prop="email">
        <el-input v-model="form.tableNames.toString()" style="width: 245px;"/>
      </el-form-item>
      <el-form-item label="条件">
        <el-input v-model="form.condition" style="width: 380px;" rows="12" type="textarea"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
    import {exportDataToExcelZip} from '@/api/code-tools'
    import {downloadFileFunction} from '@/api/downloadFile'

    export default {
        data() {
            return {
                dialog: false,
                loading: false,
                form: {tableNames: [], condition: ''},
                currentTableNames: this.tableNames
            }
        },
        methods: {
            cancel() {
                this.resetForm()
            },
            doSubmit() {
                let idsTableNames = this.form.tableNames;
                console.log(idsTableNames);
                let condition = this.form.condition;
                console.log(condition);
                let params = {
                    'tableNames': idsTableNames.toString(), 'condition': condition
                };
                let outputFileName = idsTableNames + `导出的数据.zip`;
                this.commonGeneratorCodeZip(params, outputFileName);
                this.dialog = false;
            },
            resetForm() {
                this.dialog = false;
                this.$refs['form'].resetFields();
            },
            commonGeneratorCodeZip(generatorCodeParams, outputFileName) {
                exportDataToExcelZip(generatorCodeParams).then(res => {
                    this.loading = false;
                    downloadFileFunction(res, outputFileName);
                    this.$notify({
                        title: '下载成功',
                        type: 'success',
                        duration: 2500
                    })
                }).catch(err => {
                    this.loading = false;
                    console.log(err)
                })
            }

        }
    }
</script>

<style scoped>

</style>
